package com.example.windowdemo.window;

import android.content.Context;
import android.view.View;
import android.view.WindowManager;

/**
 * @author: njb
 * @date: 2023/7/31 23:45
 * @desc:
 */
public class WindowManagerHelper {
    private static volatile WindowManagerHelper sInstance;
    private WindowManager mWindowManager;

    private WindowManagerHelper(Context context) {
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    }

    public static WindowManagerHelper getInstance(Context context) {
        if (sInstance == null) {
            synchronized (WindowManagerHelper.class) {
                if (sInstance == null) {
                    sInstance = new WindowManagerHelper(context);
                }
            }
        }
        return sInstance;
    }

    public void addView(View view, WindowManager.LayoutParams params) {
        mWindowManager.addView(view, params);
    }

    public void removeView(View view) {
        mWindowManager.removeView(view);
    }
}
